package com.dq.domain.goods;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @创建人 gewenzhen
 * @创建时间 2019/9/16
 * @描述
 */
@Data
@Entity
@ApiModel(value = "商品规格")
public class GoodSpecification extends BaseEntity implements VO.ToVO {
    @ApiModelProperty(value = "商品")
    @ManyToOne
    public Goods goods;
    @ApiModelProperty(value = "规格")
    @ManyToOne
    public Specification specification;
    @ApiModelProperty(value = "值")
    public String value;
    @ApiModelProperty(value = "图片")
    public String logoUrl;

    @Data
    @ApiModel(value = "产品视图")
    public static class Vo implements VO {
        @ApiModelProperty(value = "规格id")
        private Long id;
        @ApiModelProperty(value = "规格")
        @ManyToOne
        private Specification.Vo specification;
        @ApiModelProperty(value = "规格名")
        private String name;
        @ApiModelProperty(value = "值")
        private String value;
        @ApiModelProperty(value = "图片")
        private String logoUrl;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.specification != null ? this.specification.getId() : null;
        vo.specification = isRecursion ? (Specification.Vo) VO.inCaseNull(this.specification, false) : null;
        vo.name = this.specification != null ? this.specification.getName() : "";
        vo.value = this.value;
        vo.logoUrl = this.logoUrl;
        return vo;
    }
}
